execute.js
execute.js
is configuration of JavaScript logic when action is executed.
With predefined variables, user can create their own logic for action.
Expected input/output
- Execution input
- Contains request body data for API execution.
- needs to follow the schema/variables configured in
data.json
.
- Execution output
- output will contain result data from API execution for further executions.
- e.g. Action(gmail email.send) -> Output(sent email info)
- needs to follow the schema/output configured in
data.json
.
- output will contain result data from API execution for further executions.
Example execute.js
try {
const message_data = {
"to": input.data.to,
"cc": input.data.cc || [],
"bcc": input.data.bcc || [],
"from": input.data.from_name ? await connector.fn.string_to_qp({ "string": `${input.data.from_name} <${input.data.from}>` }) : input.data.from || "",
"subject": await connector.fn.string_to_qp({ "string": input.data.subject }),
"body": input.data.body,
"bodyType": (input.data.signature || input.data.bodyType === "html") ? "html" : "plain",
"signature": input.data.signature || ""
}
const response = await $.axios({
method: "post",
url: `https://www.googleapis.com/gmail/v1/users/me/messages/send`,
headers: {
"Authorization": `Bearer ${serivce.token}`,
"Content-Type": "application/json"
},
data: {
"raw": await connector.fn.create_raw_message(message_data),
"labelIds": input.data.labelIds || []
}
})
const email_info = await connector.fn.get_email_info({ "id": response.data.id, "connector_token": serivce.token }, $)
email_info["message_info"] = await connector.fn.get_payload_info(email_info.payload)
return email_info
} catch (error) {
throw error
}
Helpful?